<?php
// 处理维修员动作
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");
//设置默认时区
date_default_timezone_set('PRC');
$now_date = date('Y-m-d H:i:s', time());
if (empty($_GET['action'])) {
    die("<script>alert('非法请求');location.href='../r-main.php';</script>");
} else {
    $action = $_GET['action'];
    if ($action == 'over_fix') {
        $fix_id = $_GET['fix_id'];
        $sql = "UPDATE tb_fixinfo_request SET fix_status = '2', fix_endtime = '" . $now_date . "' WHERE fix_id = '" . $fix_id . "'";
        $res = mysqli_query($conn_DB, $sql);
        if ($res) {
            echo "<script>alert('操作成功');location.href='../r-main.php';</script>";
        } else {
            echo "<script>alert('操作失败请重试！');history.go(-1);</script>";
        }
    }
    if ($action == 'update_info') {
        $r_id = $_GET['r_id'];
        $r_name = $_GET['r_name'];
        $r_phone = $_GET['r_phone'];
        $sql = "UPDATE tb_repairer SET r_name = '" . $r_name . "', r_phone = '" . $r_phone . "' WHERE r_id = '" . $r_id . "'";
        $res = mysqli_query($conn_DB, $sql);
        if ($res) {
            $sql_1 = "SELECT * FROM tb_repairer WHERE r_id = '" . $r_id . "'";
            if ($res_1 = mysqli_query($conn_DB, $sql_1)) {
                if (!session_id()) {
                    session_start();
                    $_SESSION['REPAIRER'] = mysqli_fetch_array($res_1);
                }
                echo "<script>alert('操作成功');location.href='../r-info.php';</script>";
            }
        } else {
            echo "<script>alert('操作失败请重试！');history.go(-1);</script>";
        }
    }
    if ($action == 'update_pwd') {
        $r_id = $_GET['r_id'];
        $r_old_pwd = $_GET['r_old_pwd'];
        $r_pwd = $_GET['r_new_pwd'];
        $sql = "SELECT * FROM tb_repairer WHERE r_id = '" . $r_id . "'";
        $res = mysqli_query($conn_DB, $sql);
        if ($res) {
            $row = mysqli_fetch_assoc($res);
            if ($row['r_password'] == $r_old_pwd) {
                $sql = "UPDATE tb_repairer SET r_password = '" . $r_pwd . "' WHERE r_id = '" . $r_id . "'";
                $res = mysqli_query($conn_DB, $sql);
                if ($res) {
                    echo "<script>alert('操作成功,即将退出登录！');location.href='logout.php';</script>";
                } else {
                    echo "<script>alert('操作失败请重试！');history.go(-1);</script>";
                }
            } else {
                echo "<script>alert('原密码错误！');history.go(-1);</script>";
            }
        } else {
            echo "<script>alert('操作失败请重试！');history.go(-1);</script>";
        }
    }
}
